package com.bwstudio.demo.consumer.message.template;

import org.springframework.transaction.annotation.Transactional;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class MsgProcessTemplateV2<T> {

	public final void doProcess(String jsonStr) {
		log.info("开始消费消息:{}", jsonStr);
		try {
			T t = doParse(jsonStr);
			msgBodyValidate(t);
			checkTxNoIsExisted(t);
			doUpdateDB(t);
		} catch (Exception e) {
			log.error("topic_txmsg 消费失败", e);
			throw new RuntimeException(e.getMessage(), e);
		}
	}

	protected abstract T doParse(String jsonStr);
	
	protected abstract void msgBodyValidate(T t) throws RuntimeException;
	
	protected abstract void checkTxNoIsExisted(T t) throws RuntimeException;
	
	protected abstract void doUpdateDB(T t);

}
